//
//  FJDetailCommitCell.swift
//  FruitJuice
//
//  Created by Rae on 2024/1/3.
//

import UIKit

class FJDetailCommitCell: UITableViewCell {
    
    private let iconImageView       = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(20).end()
    private let nameLabel           = c_make_ex(UILabel.self)
        .color(.black).font(18.font_bold).end()
    private let timeLabel           = c_make_ex(UILabel.self)
        .color(.black.alpha(0.45)).font(14.font_regular).end()
    private let reportButton        = c_make_ex(UIButton.self)
        .image("FJ_Home_Detail_report").end()
    private let contentLabel        = c_make_ex(UILabel.self)
        .color(.black).font(18.font_regular).line(0).end()
    
    var blackClosure: ((_ userId: String) -> Void)?
    
    var model:InfoUtil.commentDta?{
        didSet{
            guard let md = model else {
                return
            }
            iconImageView.loadImage(url: md.userImage)
            nameLabel.text = md.userName
            contentLabel.text = md.msg
            timeLabel.text = md.createTime
            if md.userId == USEINFOMODEL.id {
                reportButton.isHidden = true
            }else{
                reportButton.isHidden = false
            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews {
            iconImageView
            nameLabel
            timeLabel
            reportButton
            contentLabel
        }

        iconImageView.leading(15).top(0).size(40)
        nameLabel.leading(65).top(2).trailing(65)
        timeLabel.leading(65).top(23).trailing(65)
        reportButton.trailing(15).size(30)
        reportButton.CenterY == iconImageView.CenterY
        contentLabel.leading(15).trailing(15).bottom(15)
        contentLabel.Top == iconImageView.Bottom + 10
        
        reportButton.addTarget(self, action: #selector(blackUser), for: .touchUpInside)
    }
    
    @objc private func blackUser(){
        if let userId = model?.userId {
            blackClosure?(userId)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
